package se.liu.oschi129.game.objects;

import java.awt.Color;
import java.awt.Font;

import se.liu.oschi129.animation.Animation;
import se.liu.oschi129.animation.animationspace.AnimationSpace;
import se.liu.oschi129.font.fontspace.FontSpace;
import se.liu.oschi129.world.model.World;
import se.liu.oschi129.world.model.WorldGraphics;
import se.liu.oschi129.world.objects.WorldStaticObject;

/**
 * This is the status bar displayed in the top left corner of the screen.
 * The status bar shows the number of lives and coins the player has collected
 * and it also displays the remaining time on the stage.
 * 
 * @author oschi129
 */
public class ObjectStatusBar extends WorldStaticObject {

	// Subanimations inside the status bar
	private final Animation statusbar, lives, coins, time;
	
	// The font used in the status bar
	private final Font statusFont;
	
	// The world to read the status from
	private final World world;
	
	/**
	 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	 * - - - - - - - - - - - - Constructors - - - - - - - - - - - 
	 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	 */
	
	public ObjectStatusBar(World world) {
		// Occupy the whole room - removing drawing optimization
		super(0,0,world.getWidth(),world.getHeight());
		// Draw topmost
		setDepth(-100);
		setVisible(true);
		
		this.world = world;
		statusbar = AnimationSpace.get("img_status_bar01");
		lives = AnimationSpace.get("img_status_lives01");
		coins = AnimationSpace.get("img_status_coins01");
		time = AnimationSpace.get("img_status_time01");
		statusFont = FontSpace.get("font_status", 8f);
	}
	
	/**
	 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	 * - - - - - - - - - - - Public methods - - - - - - - - - - 
	 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	 */
	
	@Override public void performDrawingAction(WorldGraphics worldg) {
		
		double viewX = world.getView().getViewX();
		double viewY = world.getView().getViewY();
		double viewWidth = world.getView().getViewWidth();
		
		worldg.setColor(Color.BLACK);
		worldg.fillRect(viewX, viewY, viewWidth, 32);
		worldg.drawAnimation(viewX,viewY+4,statusbar);
		worldg.drawAnimation(viewX+8,viewY+17,lives);
		worldg.drawAnimation(viewX+128,viewY+8,coins);
		worldg.drawAnimation(viewX+120,viewY+17,time);
		worldg.setColor(Color.WHITE);
		worldg.setFont(statusFont);
		worldg.drawText(viewX+135,viewY+15,String.format("%02d",world.getCoins()));
		worldg.drawText(viewX+127,viewY+24,String.format("%03d",(int) world.getTime()));
		worldg.drawText(viewX+32,viewY+24,String.format("%02d",world.getLives()));
		worldg.drawText(viewX+56,viewY+24,String.format("%07d",world.getPoints()));
		worldg.drawText(viewX+8,viewY+15,"World 1");
	}
	
}
